package org.cloudie.docs.editor.client.icons.desktop;

import org.cloudie.docs.editor.client.content.contextmenus.TrashIconContextMenu;
import org.cloudie.docs.editor.client.parts.DesktopPart;
import org.cloudie.docs.editor.client.widgets.ContextMenu;
import org.cloudie.docs.editor.client.widgets.DesktopIcon;

import com.google.gwt.user.client.ui.Widget;

public class TrashDesktopIcon extends FolderDesktopIcon {
  
  protected boolean isEmpty = true;
  
  public TrashDesktopIcon(String id, String label, boolean isEmpty) {
	super(id, label, "filesystems/trashcan_empty_alt");
	this.isEmpty = isEmpty;
  }

  public boolean isEmpty() {
    return isEmpty;
  }

  public void setEmpty(boolean isEmpty) {
    this.isEmpty = isEmpty;
    if (isEmpty) {
      this.setImage("filesystems/trashcan_empty_alt");
    } else {
      this.setImage("filesystems/trashcan_full");
    }
  }

  @Override
  public boolean allowsDropping(Widget receiver) {
	if (receiver instanceof DesktopPart) {
	  return true;
	} else if (receiver instanceof DesktopPart.IconTray) {
	  return true;
	}
  	return false;
  }

  @Override
  public boolean allowsDropping() {
  	return true;
  }
  
  @Override
  public boolean acceptsReceives(Widget dropped, boolean isFinal) {
    if (dropped instanceof DesktopIcon) {
	  //DesktopIcon di = (DesktopIcon) dropped;
	  //boolean c = !isFinal || Window.confirm("The item \"" + di.getLabel() + "\" will be deleted.");
	  return true;
    }
    return false;
  }

  @Override
  public ContextMenu getContextMenu() {
	TrashIconContextMenu menu = TrashIconContextMenu.get();
	menu.setTarget(this);
	return menu;
  }
  
}
